package com.electromagnetic.industry.software.manage.config;

import cn.hutool.core.io.FileUtil;
import com.electromagnetic.industry.software.common.enums.DataOwnEnum;
import com.electromagnetic.industry.software.common.util.EleCommonUtil;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.File;
import java.util.List;

@Component
public class ElePropertyConfig {

    @Value("${data.ele.tmp.path}")
    private String eleTmpPath;

    @Value("${data.sys.prj.path}")
    private String sysPrjPath;

    @Value("${data.sys.upload.path}")
    private String sysUploadPath;

    @Value("${data.sys.download.path}")
    private String sysDownloadPath;

    @Value("${data.user.prj.path}")
    private String userPrjPath;

    @Value("${data.user.upload.path}")
    private String userUploadPath;

    @Value("${data.user.download.path}")
    private String userDownloadPath;

    @Value("${data.repo.prj.path}")
    private String repoPrjPath;

    @Value("${data.repo.upload.path}")
    private String repoUploadPath;

    @Value("${data.repo.download.path}")
    private String repoDownloadPath;

    @Value("${data.import.prj.path}")
    private String importPrjPath;

    @Value("${data.import.upload.path}")
    private String importUploadPath;

    @Value("${data.import.download.path}")
    private String importDownloadPath;

    @Getter
    @Value("${backup.mysql.script.path}")
    private String backupMysqlScriptPath;

    @Getter
    @Value("${tmp.file.store.hour}")
    private int tmpFileStoreHour;

    @Getter
    @Value("${backup.remote.host}")
    private String remoteHost = "";

    @Getter
    @Value("${backup.remote.port}")
    private int remotePort;

    @Value("${winPrefix}")
    private String winPrefix = "";

    @Getter
    @Value("${backup.mysql.path}")
    private String sqlDirs;

    @Getter
    @Value("${ai.store.max.docs:200}")
    private Integer aiMaxDocs;

    @Getter
    @Value("${prj.folder.max.length}")
    private Integer prjFolderMaxLength;

    @Value("${prjRootPath}")
    private String prjRootPath;

    @Value("${allow.upload.file.types}")
    private String allowUploadFileTypes;

    @Value("${ai.file.upload.store.dir}")
    private String aiFileUploadStoreDir;

    @Getter
    @Value("${file.enc.passwd}")
    private String fileEncPasswd;

    @Getter
    @Value("${login.enc.passwd}")
    private String loginEncPasswd;

    public String getAiFileUploadStoreDir() {
        if (EleCommonUtil.isWinOs()) {
            return FileUtil.normalize(winPrefix + File.separator + aiFileUploadStoreDir);
        }
        return FileUtil.normalize(aiFileUploadStoreDir);
    }

    public List<String> getAiAllowUploadFileTypes() {
        return List.of(allowUploadFileTypes.replace(" ", "").split(","));
    }

    public String getEleTmpPath() {
        if (EleCommonUtil.isWinOs()) {
            return winPrefix + prjRootPath + eleTmpPath;
        }
        return prjRootPath + eleTmpPath;
    }

    public String getSysPrjPath() {
        if (EleCommonUtil.isWinOs()) {
            return winPrefix + prjRootPath + sysPrjPath;
        }
        return prjRootPath + sysPrjPath;
    }

    public String getSysUploadPath() {
        if (EleCommonUtil.isWinOs()) {
            return winPrefix + prjRootPath + sysUploadPath;
        }
        return prjRootPath + sysUploadPath;
    }

    public String getSysDownloadPath() {
        if (EleCommonUtil.isWinOs()) {
            return winPrefix + prjRootPath + sysDownloadPath;
        }
        return prjRootPath + sysDownloadPath;
    }

    public String getUserPrjPath() {
        if (EleCommonUtil.isWinOs()) {
            return winPrefix + prjRootPath + userPrjPath;
        }
        return prjRootPath + userPrjPath;
    }

    public String getUserUploadPath() {
        if (EleCommonUtil.isWinOs()) {
            return winPrefix + prjRootPath + userUploadPath;
        }
        return prjRootPath + userUploadPath;
    }

    public String getUserDownloadPath() {
        if (EleCommonUtil.isWinOs()) {
            return winPrefix + prjRootPath + userDownloadPath;
        }
        return prjRootPath + userDownloadPath;
    }

    public String getRepoPrjPath() {
        if (EleCommonUtil.isWinOs()) {
            return winPrefix + prjRootPath + repoPrjPath;
        }
        return prjRootPath + repoPrjPath;
    }

    public String getRepoUploadPath() {
        if (EleCommonUtil.isWinOs()) {
            return winPrefix + prjRootPath + repoUploadPath;
        }
        return prjRootPath + repoUploadPath;
    }

    public String getRepoDownloadPath() {
        if (EleCommonUtil.isWinOs()) {
            return winPrefix + prjRootPath + repoDownloadPath;
        }
        return prjRootPath + repoDownloadPath;
    }

    public String getImportPrjPath() {
        if (EleCommonUtil.isWinOs()) {
            return winPrefix + prjRootPath + importPrjPath;
        }
        return prjRootPath + importPrjPath;
    }

    public String getImportUploadPath() {
        if (EleCommonUtil.isWinOs()) {
            return winPrefix + prjRootPath + importUploadPath;
        }
        return prjRootPath + importUploadPath;
    }

    public String getImportDownloadPath() {
        if (EleCommonUtil.isWinOs()) {
            return winPrefix + prjRootPath + importDownloadPath;
        }
        return prjRootPath + importDownloadPath;
    }

    public String getUploadDataDir(int dataOwnCode) {
        if (DataOwnEnum.isSysCode(dataOwnCode)) {
            return getSysUploadPath();
        } else if (DataOwnEnum.isUserCode(dataOwnCode)) {
            return getUserUploadPath();
        }
        return getRepoUploadPath();
    }

    public String getDownloadDataDir(int dataOwnCode) {
        if (DataOwnEnum.isSysCode(dataOwnCode)) {
            return getSysDownloadPath();
        } else if (DataOwnEnum.isUserCode(dataOwnCode)) {
            return getUserDownloadPath();
        }
        return getRepoDownloadPath();
    }


}
